package me;

import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;

/**
 * @author yexy
 * @date 2020/6/30 4:58 PM
 * @description
 */
public class Client {

    public static void main(String[] args) {

        Socket socket = null;
        ObjectInputStream objectInputStream = null;
        ObjectOutputStream objectOutputStream = null;
        try {
            socket = new Socket("127.0.0.1",9999);

            objectOutputStream = new ObjectOutputStream(socket.getOutputStream());

            User user = new User("admin","12342256");
            UserMessage userMessage = new UserMessage();
            userMessage.setUser(user);
            objectOutputStream.writeObject(userMessage);

            objectInputStream = new ObjectInputStream(socket.getInputStream());
            UserMessage result = (UserMessage) objectInputStream.readObject();
            if (result.getType().equals("success"))
                System.out.println("登录成功！");
            else
                System.out.println("登录失败！");

        } catch (Exception e) {
            e.printStackTrace();
        }finally
        {
            try {
                if (objectOutputStream != null)
                    objectOutputStream.close();
                if (objectInputStream != null)
                    objectInputStream.close();
                if (socket != null)
                    socket.close();
            }catch (Exception e){
                e.printStackTrace();
            }


        }
    }
}
